import string, os, sys
import struct
import random

def random_str(randomlength=8):
    a = list(string.ascii_letters)
    random.shuffle(a)
    return ''.join(a[:randomlength])


def process(filepath):
	#print filepath
	fileData = open(filepath,'r')
	chunk = fileData.read(3)
	
	if cmp(chunk,'xmu')==0:
		return
		
	fileData.seek(0)
	content = fileData.read()
	fileData.close()

	text = 'xmu'+random_str(7) + content
	fileData = open(filepath,'w')
	fileData.write(text)
	fileData.close()


dir = os.getcwd()
print dir
if len(sys.argv)>1:
	dir = sys.argv[1]

files = os.listdir(dir)
for f in files:
	if cmp(f,sys.argv[0])==0:
		continue

	if os.path.splitext(f)[1] == '.jpg':
		filepath = dir + os.sep + f
		process(filepath)	
	if os.path.splitext(f)[1] == '.JPG':
		filepath = dir + os.sep + f
		process(filepath)	
	